﻿using System;
using System.Collections.Generic;
using UnityEngine;

public class AttrFactory : IAttrFactory
{
    //存放基础角色属性
    private Dictionary<Type, CharacterBaseAttr> mCharacterBaseAttrDic = null;

    private Dictionary<WeaponType, WeaponBaseAttr> mWeaponBaseAttrDic = null;

    public AttrFactory()
    {
        InitCharacterBaseAttr();
        InitWeaponBaseAttr();
    }

    private void InitCharacterBaseAttr()
    {
        mCharacterBaseAttrDic = new Dictionary<Type, CharacterBaseAttr>();
        mCharacterBaseAttrDic.Add(typeof(SoldierRookie),
            new CharacterBaseAttr("下士", 80, 2.5f, "RookieIcon", "Soldier2", 0));
        mCharacterBaseAttrDic.Add(typeof(SoldierSergeant),
            new CharacterBaseAttr("中士", 90, 3f, "SergeantIcon", "Soldier3", 0));
        mCharacterBaseAttrDic.Add(typeof(SoldierCaptain),
            new CharacterBaseAttr("上尉", 100, 3f, "CaptainIcon", "Soldier1", 0));

        mCharacterBaseAttrDic.Add(typeof(EnemyElf), new CharacterBaseAttr("小精灵", 100, 3, "ElfIcon", "Enemy1", 0.2f));
        mCharacterBaseAttrDic.Add(typeof(EnemyOgre), new CharacterBaseAttr("怪物", 120, 4, "OgreIcon", "Enemy2", 0.25f));
        mCharacterBaseAttrDic.Add(typeof(EnemyTroll), new CharacterBaseAttr("巨魔", 200, 1, "TrollIcon", "Enemy3", 0.3f));
    }

    public CharacterBaseAttr GetCharacterBaseAttr(Type type)
    {
        if (!mCharacterBaseAttrDic.TryGetValue(type, out var Role))
        {
            Debug.LogError($"无法根据类型-{type}-创建角色基础属性!");
            return null;
        }

        return Role;
    }

    private void InitWeaponBaseAttr()
    {
        mWeaponBaseAttrDic = new Dictionary<WeaponType, WeaponBaseAttr>();
        mWeaponBaseAttrDic.Add(WeaponType.Gun, new WeaponBaseAttr("手枪", 20, 5, "WeaponGun"));
        mWeaponBaseAttrDic.Add(WeaponType.Rifle, new WeaponBaseAttr("步枪", 30, 7, "WeaponRifle"));
        mWeaponBaseAttrDic.Add(WeaponType.Rocket, new WeaponBaseAttr("火箭", 40, 9, "WeaponRifle"));
    }

    public WeaponBaseAttr GetWeaponBaseAttr(WeaponType weaponType)
    {
        if (!mWeaponBaseAttrDic.TryGetValue(weaponType, out var attr))
        {
            Debug.LogError($"无法根据类型-{weaponType}-创建角色基础属性!");
            return null;
        }

        return attr;
    }
}